Repository navigation
Reimplement UpdateDairyFarmer from gynt's units branch (100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on) - #513
Merged
Conversation
The original compares the dairy farm's production stage as a signed byte: UpdateDairyFarmer (0x00554500) loads it with `mov al, byte ptr [ebp + 0xf987cc]` and tests `cmp al, 3` / `jl` at 0x00554694 and `cmp al, 4` / `jg` at 0x0055469C. As a `byte` the field needed a `(char)` cast at each of those four tests (the next commit); as a `char` it needs none. Size and offset are unchanged. Its only other user, UpdateDairyFarm (0x004167E0), stores small constants into it and compares it for equality. Real narrow builds of main e3646a8 with this change (259 sources: main's /GL list, UpdateDairyFarmer with its callee closure, every file of a function-visibility group that touches them), BUILD_OK, give UpdateDairyFarm 97.9 / 85.2 with the same reccmp listing as the full builds with the `byte` header, with OPENSHC_FUNCTION_VISIBILITY_UNITS off and on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ION_VISIBILITY_UNITS on) Units::UpdateDairyFarmer, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; his commit on the file: dbaa980 at 55.05%), through the forms on our development branches (59a26bd59a 77.7%, 39eef8ad2a 83.1%, 3afe6a38ec 90.3%, 93d7440dcf 93.9% under that branch's /GL list). The text reads a true 100.0 / 100.0 when getResourceCountThatCanBeDeposited is not visible to it, which is how the original was built (see the end), and main's function-visibility manifest says so already: its UpdateDairyFarmer entry (since PR 399) names the six callees this unit must see, and with OPENSHC_FUNCTION_VISIBILITY_UNITS on it reads 100.0 / 100.0. With the option off, the default, its /GL line shows it every /GL body, getResourceCountThatCanBeDeposited included, and it reads 85.2 / 76.9. The statements are his; what the text needed is how they are arranged. 1. Unit accesses go through DAT_CurrentUnitSlotID::instance, except the setDestinationForUnit call of the walk to the field and the getResourceCountThatCanBeDeposited call, which read the unit through the unitID local taken at the top (a block-level search chose them). The original keeps the slot in a register and loads it again only behind a call that may change it. No comment says so in the code: gynt asked on PR 393 for no comments on why unit accesses index through the slot; the PR text explains it. 2. The states are one if / else-if chain whose arms fall out of it, with no trailing returns. 3. After that setDestinationForUnit the slot is read again in both arms: the success arm into unitID, the failure arm through DAT_CurrentUnitSlotID, and the stores and the hasUnitReachedDestination test after the merge go through DAT_CurrentUnitSlotID. 4. The last store reads the unit's workplace again rather than using `workplace`, as the original does (a comment says so; `buildings[workplace]` reads 0.9886 against 0.9959 in quick_diff). 5. Style: no `(char)` casts on the fade countdown, the AnimationFrameData tables (char in main's headers) and the production stage (char since the previous commit); SetStateToFreetimeWalking's BOOLEnum tested by truthiness; steps by one written `++` / `--`; destinationNeeded 2 as DNE_UNKNOWN_2; `int const storage`; the BOOLEnum.hpp include and the DestinationNeededEnum using dropped (nothing here names BOOLEnum: TRUE and FALSE are the Windows macros from the precompiled header's Windows.h). Code generation is the same in both modes. Visibility. The original reads the slot again right behind getResourceCountThatCanBeDeposited (call at 0x005549BC, `mov eax, dword ptr [0xee0fc8]` at 0x005549C3), so its compiler did not see that callee's body. addResourceToGranary needs that body (main's manifest says so), and under /GL every listed file sees every other, so this unit sees it too and keeps the slot cached. The manifest can say both: getResourceCountThatCanBeDeposited stays in the wrapper of addResourceToGranary and getResourceSpace, and this unit's wrapper (the units' one) holds IncrementAndOptionalUpdateAVValueRelated, SetStateToFreetimeWalking, CheckUnitProductionPaused, ComputeGoodsProduced, checkIfCitizenUnitIsAliveBasedOnState and hasUnitReachedDestination, which it must see. Measured with full all-on builds of main e3646a8 with this function (every .cpp under src/OpenSHC except the 12 that don't compile on main, every function and data resolver on, BUILD_OK, 0 failed), on the text before the review fixes (the `byte` header, the casts, `!= 0`, no comment; the same listing in quick_diff and quick_gl): - option off, the default build: 85.2 / 76.9, against main 655adce built the same way (the baseline on hand; main has moved only by PR 510 since, whose four functions are new there); - option on: 100.0 / 100.0, no diff entry, against main e3646a8 built the same way. Nothing on main reads lower in either mode. The only other changes are Constructor_Menu and handleMenuItems, which flip between 98.4 / 97.9 and 100 with the image layout (reccmp names the constants 0x11000000 and 0x21000000 after whatever of ours lands at that address). The final text, with the char header of the previous commit: real narrow builds (259 sources: main's /GL list, this unit with its callee closure, every file of a function-visibility group that touches them), BUILD_OK, give 85.2 / 76.9 off and 100.0 / 100.0 on, each with the same reccmp listing as the full builds, and UpdateDairyFarm, the field's other user, reads as on main in both modes. Those builds had two more comment lines, since dropped. The status line carries the default build's number. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt
added a commit
that referenced
this pull request
Nov 29, 2026
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt
previously approved these changes
Nov 29, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 29, 2026
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt
previously approved these changes
Nov 29, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Nov 29, 2026
The only conflict was the end of cmake/compiler-flags-gl.txt, where both sides added lines; both are kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gynt
approved these changes
Nov 29, 2026
This was referenced Nov 29, 2026
gynt
added a commit
to gynt/OpenSHC
that referenced
this pull request
Dec 2, 2026
…Ladderman, UpdateTunneler and UpdateFireThrower from gynt's units branch, under /GL (100%) (sourcehold#516) * reimplement: SHC_3BB0A8C1_0x005477C0 100.0% Reimplemented Units::UpdateChild at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; his commits on the file: 06ebdf6 at 25.50% and the style commit 948147d at 27.32%, then 974c32f's clang-format), through the forms on our development branches. The statements are his; what the text needed is how they are arranged and where three values live. Nothing behaves differently from the draft. 1. The fifteen "stay at home while enemies are around" tests as nested ifs with an early return in each arm: `if (mode != skirmish) { if (sumOfTotalEnemyUnitsCount != 0) {go home} } else if (someCount46 == 0) {go home}`. A combined condition compiles to setcc, where the original branches (0x0054792C .. 0x00547954 and fourteen more). The draft's polarity was already the original's. 2. One function-level `int i;` for every loop, and one `short random;` for the RNG value in states 15, 16 and 18. The compiler orders its stack slots by use count: the original keeps the loop counter in one slot ([esp + 0x10] at 0x0054823A, 0x005487BB and 0x00548B56) and the RNG value in one ([esp + 0x1c] at 0x00548744 and 0x00548A3A); with a variable per loop and per state the slots come out in another order. 3. `random` is a short because the original divides it with idiv (state 15: idiv esi at 0x00548A47 and 0x00548A5B). `v % 7` of an int variable compiles to a multiply by the inverse; of a short (promoted) or of a global read it divides. For the same reason state 0 switches on `SEC_RNG::instance.currentNumber2 % 25` (cdq / idiv at 0x0054795F / 0x00547965). State 18 takes its two offsets from `random` too: the original loads the lord's coordinates in front of each division and keeps the lord in a stack slot (0x00548D2C). 4. State 0's switch cases end in `break;` and the one nextRandomNumber2() after the switch serves them all (the original's cases end in their own jumps to it, 0x005479A4 .. 0x00547AA3; a call and a return in each case gave other epilogues). 5. The states after state 16 as one else-if chain without the returns that closed them, the alive check, the disappear state and the fallback in its final else. States 14 and 15 then jump forward into state 18's `destinationNeeded = 1; return` (0x005489BF, 0x00548AF5 -> 0x00548DF4) as in the original, which keeps the later copy of a tail the states share; with the returns the compiler kept the first. 6. Smaller arrangements: state 16's `found` flag set to FALSE in front of the destination test ([esp + 0x20] at 0x00548759), its gfxNumber written in both arms of the frame test, the play rounds stored to this child and then copied to the other one (lea eax, [edx + 1] at 0x00547DBB and 0x005482EA), and state 18's three stores in the original's order (129, 1, 16 at 0x00548CFC .. 0x00548D0E). 7. The fade countdown without its `(char)` casts: the field is a char in main's Unit.hpp. On main, this round's text pass: the BOOLEnum computeLadderClimbPath tested by truthiness; `(UnitState)10` and 13 to 16 as US_UNKNOWN_10 to US_UNKNOWN_16 (17 and 18 have no name yet); the `(char)` casts on the seven Frames_Shared_UnitClimbingUp reads dropped (char in main's AnimationFrameData.hpp); `const` on owner and the home, other, offset and leader locals; the comments on the shared loop counter, the shared random value and the five ternaries say why without addresses; one comment on the two sign tests of the fade step; the worker-list comment reworded; after the review, the five random updateTickTracker stores in one form without a cast, `found` as a BOOLEnum local, and the counter's comment says that state 17 reads it after its search loop. The quick_diff listing is the same before and after. Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): a narrow build on main 4ddb41a, before sourcehold#514 and sourcehold#513 merged (468 files: main's /GL files, the six units of this round with their callee closures, every file of a function-visibility group that touches them) and a full build of every file of the branch on main 859c1fe (2,993 files, 3,011 functions), each once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK all four. It reads 100.0 / 100.0 with the option off in both. With it on it reads 47.3 / 46.5 in both: it has no entry in cmake/function-visibility.txt, so the callees the units' wrapper holds leave the /GL list in that mode (main's UpdatePriest, a /GL unit without an entry, reads 72.0 / 68.9 there for the same reason). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x005521D0 100.0% Reimplemented Units::UpdateWheatFarmer at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; his commits on the file: 94a6fd5 at 39.73% and the style commit 98423cb at 24.52%), through the forms on our development branches. The statements are his; what the text needed is how they are arranged: 1. The "walk to the next tile" tail (changeDestinationByAmount(slot, 1) and the two tile stores) is written out at the end of each of the four states that reach it, each with its own return, instead of once behind the else-if chain. The original has one physical copy in state 4 (0x0055265D) and the others join it at different depths: state 1 jumps to its start, state 7 behind its own push (0x005529EE to 0x0055265F), the store state behind its own two pushes (0x00552D90 to 0x00552666). Joins at different depths are separate copies in the source that the compiler merged. 2. What stands behind the chain is `if (DAT_UnitHasBecomeIdle != 0) { state = 110; }`, shared by the two death animations (state 111 and the alive check): both end in `gfx = frame + N;` and fall out of the chain. The original's join stands behind the alive check's block (0x00552EC1) and state 111 jumps forward into it (0x00552E5B). With one idle test per block the compiler kept the first block's copy. 3. The two walk ternaries as `index < size ? walking : arrived` (setge / and -0x80 / add 0x81). 4. State 8: the DamageLayer store written first (the tile index is loaded in front of the unit's stores). 5. Taking goods to the store: the walk tail in the if of a successful setDestinationForUnit, the failure behind it. On main, this round's text pass: the BOOLEnum isFarmTileReadyForWheatStageChange tested by truthiness (four places); the shared states by their UnitState names (US_DISAPPEAR, US_UNKNOWN_121, US_UNKNOWN_108, US_DEATH_01), with US_DISAPPEAR stored through state.generic as the file's other shared states; the farm's grow state stored through state.generic without a cast, as main's UpdateHopsFarmer does; the `(short)` casts on `farmerDestinationTile - addXgetTile` and on DirectionAlgorithmState's orientation dropped; the `(char)` casts on the six frame-table reads dropped; `const` on the locals; one comment on `idle` (read once: with two global reads the listing changes); the two ternary comments without addresses; after the review, the two lookups of the wheat store under one name (`storage`, as main's UpdateHopsFarmer and UpdateDairyFarmer name it), and a comment on the second read of the workplace (with `farm` instead, the listing changes). The quick_diff listing is the same before and after. Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): a narrow build on main 4ddb41a, before sourcehold#514 and sourcehold#513 merged (468 files: main's /GL files, the six units of this round with their callee closures, every file of a function-visibility group that touches them) and a full build of every file of the branch on main 859c1fe (2,993 files, 3,011 functions), each once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK all four. It reads 100.0 / 100.0 with the option off in both. With it on it reads 37.8 / 35.9 in the narrow build and 37.7 / 35.9 in the full one: it has no entry in cmake/function-visibility.txt, so the callees the units' wrapper holds leave the /GL list in that mode (main's UpdatePriest, a /GL unit without an entry, reads 72.0 / 68.9 there for the same reason). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x0055C7B0 100.0% Reimplemented Units::UpdateCrossbowman at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; his commits on the file: 43f68e4 at 31.63% and the style commit 21fe19a at 40.98%), through the forms on our development branches. The statements are his; what the text needed is how they are arranged: 1. Every access reads the unit through DAT_CurrentUnitSlotID::instance; the draft's local copy `int unitID` is gone. 2. State 0's end is one if / else chain with a single return behind it: the shoot-or-not code stands in the first arm and behind the second acquireShootTarget. The original keeps the later copy (0x0055C978) and the first arm jumps forward into it (0x0055C921). With early returns our compiler keeps the first copy. 3. The move states' and the appear state's walk-speed block in the original's form: the delayed arm first, the sheet store in every arm, one arm per reason to stand still. 4. Gathering at the rally point: `((int)mapTimeInTicks + slot) % 40`, the state store written in front of the counter. 5. `int building = targetID_OR_targetBuildingID;` in front of the switch (movsx ebx at 0x0055C833, between the switch's compare and its jump). 6. The wall-attack state in the form that matched in UpdateFireThrower; the damage is `!isGateOrTower ? 4 : 2` (sete at 0x0055CE00). 7. The shoot target as an int local where the original sign-extends it once and tests the register; the aim compare is `target >= 0`. 8. The idle state's two frame tables: the `(fixedRng & 1) != 0` arm first. 9. Three height sums as `terrain + building`. quick_diff cannot see this (it folds every displacement). 10. The fade countdown is stepped with -- on the char field (a char in main's Unit.hpp). On main, this round's text pass: the BOOLEnum moveUnitToBehaviorTarget tested by truthiness (two places); `LogicLayer & 256` as LogicHelpers::L_WALL_OR_GATEHOUSE and the `(short)` on BuildingLayer dropped; `(UnitState)105` and 104 as US_RALLYING and US_CLIMBING_LADDER (123 has no name yet); the BOOLEnum array read as `!IsGateOrTowerArray[...]` instead of `== FALSE`; the `(char)` casts on the 17 frame-table reads dropped; `const` on the locals; the two ternary comments without addresses, one comment on `building` (read before the switch) and one on `damage`; the TODO on the AttackInfo blocks dropped (main models them now); after the review, comments on the `> 432` arm that can never be true, on the walk-speed arms that store the same values, and on the owner read in the wall attack (with `owner` instead, the listing changes). The quick_diff listing is the same before and after. Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): a narrow build on main 4ddb41a, before sourcehold#514 and sourcehold#513 merged (468 files: main's /GL files, the six units of this round with their callee closures, every file of a function-visibility group that touches them) and a full build of every file of the branch on main 859c1fe (2,993 files, 3,011 functions), each once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK all four. It reads 100.0 / 100.0 with the option off in both. With it on it reads 62.5 / 53.6 in both: it has no entry in cmake/function-visibility.txt, so the callees the units' wrapper holds leave the /GL list in that mode (main's UpdatePriest, a /GL unit without an entry, reads 72.0 / 68.9 there for the same reason). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x00563910 100.0% Reimplemented Units::UpdateLadderman at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; his commits on the file: 01cf3a2 at 22.89%, afda7ec at 37.19% and the style commit 3631a97 at 37.35%), through the forms on our development branches. The statements are his; what the text needed is how they are arranged: 1. The walk-speed block, three times (move to destination, appear, walking to the wall), as the original lays it out: the delayed arm first and the sheet store in every arm: if (delay != 0) { sheet = 1; if (delay > 70) { speed = -1; f30 = 0; } else { speed = 0; } } else if (runUp != 0) { sheet = 1; speed = 0; } else if (isMatchingSpeed != false) { sheet = 1; speed = 0; } (move state only) else { sheet = 1; speed = 1; } Two arms with the same stores give the original's `jne A; cmp; je B; A: ...`: the compiler merges them. One arm on || does not (the compiler lays the arms out as for &&). 2. Every access through the global slot (no unitID local): the slot's register is ecx as in the original. 3. The fade countdown is stepped with -- on the field, a char in main's Unit.hpp. The original holds -1 in eax (or eax, -1 at 0x005639E4) for the substate store (0x005639E7) and this add (0x005639FE); with the field as an unsigned char our compiler added 255 as its own immediate. On main, this round's text pass: `(UnitState)105` and `case 105` as US_RALLYING (103 has no name yet; the using goes); the `(short)` on DirectionAlgorithmState's orientation and the `(char)` casts on the six frame-table reads dropped; `const` on owner and tile; the ternary comment without its address. The quick_diff listing is the same before and after. Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): a narrow build on main 4ddb41a, before sourcehold#514 and sourcehold#513 merged (468 files: main's /GL files, the six units of this round with their callee closures, every file of a function-visibility group that touches them) and a full build of every file of the branch on main 859c1fe (2,993 files, 3,011 functions), each once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK all four. It reads 100.0 / 100.0 with the option off in both. With it on it reads 47.2 / 34.9 in both: it has no entry in cmake/function-visibility.txt, so the callees the units' wrapper holds leave the /GL list in that mode (main's UpdatePriest, a /GL unit without an entry, reads 72.0 / 68.9 there for the same reason). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x0054E6C0 100.0% Reimplemented Units::UpdateTunneler, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; his commits on the file: 192307c at 35.44%, 5a1c78e at 42.20%, then 6565c1b and 974c32f for the build and clang-format), through the forms on our development branches. It reads a true 100.0 / 100.0. The statements are his; what the text needed is how they are arranged. 1. One copy of the removal tail. State 9's failed setDestinationForUnit and the collapse state end in the same six statements (rubble flag, destroyBuilding of the workplace, two toggles, cycle = 0, REMOVE). The original has them once, in the collapse state (0x0054EFEB), and state 9 jumps there (je at 0x0054ED95). Written twice the compiler merges the copies into that same code, but the second copy still takes its turn while the argument registers are handed out: they go eax, ecx, edx in rotation, and the original's run from 0x0054ED73 to 0x0054EF2A has no gap (ecx edx eax / ecx / edx eax ecx / edx / eax ecx edx eax) where that copy's argument would stand. So state 9 says `goto removeTunnelAndUnit;`. With it the finished arm's argument is in ecx (0x0054EDD9) and its rubble flag is stored behind the push (0x0054EDE6), the two height calls take y / x / tile in edx / eax / ecx (0x0054EE45, 0x0054EE6A), the slot behind them is in edx (0x0054EE8D), and the damage call's four are in eax / ecx / edx / eax (0x0054EF09). The same text with the tail written out in state 9 reads 98.2 / 80.0 in the same build. The collapse block's `int tile` is declared without a value and set in the next line: a jump must not pass an initialiser. 2. `int building = 0;` once at the top, and the states that need a building assign to it. With several definitions the variable keeps its home on the stack as in the original (store at 0x0054E702, read on the wall path at 0x0054F2DA). 3. The entry: `calculatedOwnerPlayerIndex = owner;` goes through the slot global and the isSelectable test through the local unitID. The original has the store in front of the compare (0x0054E6F5, 0x0054E6FB); with one index expression in both, the compiler moves the compare up. 4. The gathering state (105): one `someCount29++;` behind `if (reached) { if (find...) { set the destination } else { facingDirection = 4; } }`. The compiler copies that tail itself (0x0054E884 and 0x0054E8A6). 5. The move state: one arm per reason to stand still, the run arm last, and the sheet store in every arm (it stands between the compare and its jump at 0x0054E917 .. 0x0054E923). 6. Tunneling and collapse: the tunnel frame test is `>= 24` (cmp cx, 0x18 / jl at 0x0054EE38); the collapse state's damage arm comes first, `if (frame < 65) { damage } else { collapse }`, and the collapse tests `BuildingLayer[tile] != 0` first. 7. The wall attack's end has UpdateArabianArcher's arrangement (destroyed wall, the AI's give-up tests, one `cycle = 0` end). 8. The chain's last arms: `else if (checkIfCitizenUnitIsAliveBasedOnState(slot)) { death animation } else { disappear }` (je at 0x0054F70D to 0x0054F786). 9. Two conditional expressions where the original has no branch (setg at 0x0054E7DF, sbb at 0x0054F316); the fade countdown without `(char)` casts (a char in main's Unit.hpp). 10. Names: the tunneler's own states (UnitState_Tunneler, through state.tunneler) where its enum has the value; the states every unit shares keep the generic names (105 is US_RALLYING on main). On main, this round's text pass: `(UnitState)105` as US_RALLYING (the using goes); the `(short)` casts on `targetedBuildingTile - addXgetTile` and the `(char)` casts on the 12 frame-table reads dropped; `const` on unitID, owner, state and the other locals; the comments on unitID, on the shared building variable, on the two ternaries and on the goto without addresses or scores; the TODO on the AttackInfo blocks dropped (main models them now); after the review, the states every unit shares stored through state.generic, as main's unit functions store them, and comments on the owner read in the wall attack and the tribe read in the move state (each changes the listing when replaced). The quick_diff listing is the same before and after. Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): a narrow build on main 4ddb41a, before sourcehold#514 and sourcehold#513 merged (468 files: main's /GL files, the six units of this round with their callee closures, every file of a function-visibility group that touches them) and a full build of every file of the branch on main 859c1fe (2,993 files, 3,011 functions), each once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK all four. It reads 100.0 / 100.0 with the option off in both. With it on it reads 59.6 / 56.3 in both: it has no entry in cmake/function-visibility.txt, so the callees the units' wrapper holds leave the /GL list in that mode (main's UpdatePriest, a /GL unit without an entry, reads 72.0 / 68.9 there for the same reason). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * reimplement: SHC_3BB0A8C1_0x005769F0 100.0% Reimplemented Units::UpdateFireThrower at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his draft PR 204; his commits on the file: 0297f00 at 42.34% and the style commit 141a491 at 47.02%), through the forms on our development branches. The statements are his; what the text needed is how they are arranged: 1. State 0's end: the shoot-or-not code (`if (state != MOVE) { state = RELOAD; ifOnADefensive...(slot); } return;`) written out behind each of the two acquireShootTarget calls; the original joins the two copies through a pointer to the state (lea at 0x00576B3C and 0x00576BA2, the join at 0x00576BA8). The cases 105, 2 / MOVE / 123 and APPEAR are no longer nested in an if block. 2. The wall-attack state: one `cycle = 0` end behind an if / else; a failed moveUnitToBehaviorTarget only stores the state (the original computes the unit's offset twice there, 0x005770A5 and 0x005770AB); the two give-up tests each compute the danger and the tolerance themselves, the wall arm first. 3. Both walk-speed blocks in the original's form (the delayed arm first, the sheet store in every arm). 4. The fade countdown is stepped with -- on the char field (a char in main's Unit.hpp); it shares the -1 register with the substate store (or ecx, -1 at 0x00576A7B). 5. Gathering at the keep: `((int)mapTimeInTicks + slot) % 40` (cdq / idiv at 0x00576C21), `<= 160`, the state store written in front of the counter. 6. The shoot target as an int local where the original sign-extends it once and tests the register (the group leader's shot, the reload state); the building's half size as `widthOrHeight / 2`. 7. Three compares turned round again: aim `target >= 0`, fire `target > -1`, sit down `<= 400`. 8. Three height sums as `terrain + building`. quick_diff cannot see this (it folds every displacement); reccmp read 99.5 / 88.2 before it. On main, this round's text pass: the BOOLEnum getKeepLocationForAIUnit and moveUnitToBehaviorTarget tested by truthiness (four places); `(UnitState)105` and 104 as US_RALLYING and US_CLIMBING_LADDER (123 has no name yet); the `(int)` on widthOrHeight dropped (an int on main); the `(char)` casts on the 12 frame-table reads dropped; `const` on the locals; comments without addresses on the ternaries, on `building`, `damage` and the target coordinates; the TODO on the AttackInfo blocks dropped (main models them now); after the review, `> 11 * 11` for the squared throw distance, and comments on the `> 432` arm that can never be true, the owner read in the wall attack, the second `frame > 0` test and the fire state's `> -1` (each changes the listing when replaced). The quick_diff listing is the same before and after. Measured with real builds (bundled MSVC1400-SP1, function and data resolvers on locally, reccmp raw / normalised): a narrow build on main 4ddb41a, before sourcehold#514 and sourcehold#513 merged (468 files: main's /GL files, the six units of this round with their callee closures, every file of a function-visibility group that touches them) and a full build of every file of the branch on main 859c1fe (2,993 files, 3,011 functions), each once with OPENSHC_FUNCTION_VISIBILITY_UNITS off and once with it on, BUILD_OK all four. It reads 100.0 / 100.0 with the option off in both. With it on it reads 64.0 / 60.6 in both: it has no entry in cmake/function-visibility.txt, so the callees the units' wrapper holds leave the /GL list in that mode (main's UpdatePriest, a /GL unit without an entry, reads 72.0 / 68.9 there for the same reason). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * status: UpdateDairyFarmer 93.9% and UpdateEngineer 85.0% in the default build Both read higher with OPENSHC_FUNCTION_VISIBILITY_UNITS off since sourcehold#238 put more UnitsState files under /GL (for UpdateDairyFarmer, CheckUnitProductionPaused). Measured in this branch's full builds and in builds of main 859c1fe made the same way, both modes: - UpdateDairyFarmer 0x00554500: 85.2% -> 93.9% / 90.0% (normalised) off, 100.0% / 100.0% on (unchanged). - UpdateEngineer 0x00564250: 81.8% -> 85.0% / 79.6% off, 100.0% / 100.0% on (unchanged). UpdatePitchman 0x00551980 still reads 94.1% off and keeps its line. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One more Map::Units update function, from gynt's units branch
reimpl/map-units-updatefunctions(his draft #204). It is the first unit that main'scmake/function-visibility.txtalready gets right: theUpdateDairyFarmerentry from #399 names the callees it must see and leaves out the one it must not, so withOPENSHC_FUNCTION_VISIBILITY_UNITSon it reads 100.0% without any manifest change. The default build (option off) reads 85.2%, which is what the status line says. The function commit cites the draft and our steps on it, and credits gynt as co-author. One header change, in a commit of its own:Building::dairyProductionStageis achar(below).Units::UpdateDairyFarmerOPENSHC_FUNCTION_VISIBILITY_UNITSonMeasured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp (a86aceb03) with--resolve-wrapped-calls --ignore-security-cookie..cppof main e3646a8 with this function, all function and data resolvers on, built once with the option off and once with it on. Both built with 0 failures, 2,912 files. They were built before the review fixes (thebyteheader, the four casts,!= 0), which give the same listing inquick_diffandquick_gl.UI::Menu::Constructor_Menu(98.4% to 100%) andhandleMenuItems(97.9% to 100%). Earlier full builds where neither file changed showed the same jump, so it follows where functions land in the image. This PR doesn't touch them.(char)casts on the AnimationFrameData tables, which arecharin main's header. Those were dropped too, with the same listing./GLlist, UpdateDairyFarmer with its callees, and every file of a function-visibility group that touches them (259 files), with thecharheader. Both built with 0 failures. UpdateDairyFarmer reads 85.2% / 76.9% with the option off and 100.0% / 100.0% with it on, each with the same reccmp listing as in the full builds. UpdateDairyFarm, the field's other user, reads 97.9% / 85.2% in both modes with the same listing as on main.openshc-pr-fixfinds nothing to change, andopenshc-pr-checkgives 0 errors and 9 notes, all of the kinds below.What got it to 100%
It started from gynt's draft and went through our development branches, where it reached 93.9% under that branch's
/GLlist. What was left was one load the original does and we didn't:getResourceCountThatCanBeDeposited(the call at 0x005549BC,mov eax, dword ptr [0xee0fc8]at 0x005549C3), so its compiler didn't see that callee's body.addResourceToGranaryneeds the body (main's manifest says so). Under/GLevery listed file sees every other, so this unit saw it too and kept the slot in a register.getResourceCountThatCanBeDepositedstays in the wrapper ofaddResourceToGranaryandgetResourceSpace. This unit lands in the units' wrapper, which holds the six callees its entry names:IncrementAndOptionalUpdateAVValueRelated,SetStateToFreetimeWalking,CheckUnitProductionPaused,ComputeGoodsProduced,checkIfCitizenUnitIsAliveBasedOnStateandhasUnitReachedDestination.DAT_CurrentUnitSlotID, except the walk'ssetDestinationForUnitcall and thegetResourceCountThatCanBeDepositedcall, which use theunitIDread at the top. The original keeps the slot in a register and loads it again only behind calls that may change it; at those two calls it uses the value it read at the top. The code has no comment on this, since Reimplement 5 Map::Units update functions from gynt's units branch, under /GL (100%) #393's review asked for none on why unit accesses go through the slot. The states are one if / else-if chain whose arms fall out of it. After thatsetDestinationForUnit, the slot is read again in both arms.(char)casts (the fade countdown and the frame tables arecharin main's headers, the production stage ischarwith the header commit),SetStateToFreetimeWalking'sBOOLEnumtested by truthiness,++/--for steps by one,DNE_UNKNOWN_2for destination 2,int const storage, and theBOOLEnum.hppinclude and theusinggone. Nothing here namesBOOLEnum;TRUEandFALSEare the Windows macros.One header change:
Building::dairyProductionStageis acharsrc/OpenSHC/Map/Buildings/Building.hpphad the field asbyte. The original compares it signed: UpdateDairyFarmer loads it withmov al, byte ptr [ebp + 0xf987cc]and testscmp al, 3/jlat 0x00554694 andcmp al, 4/jgat 0x0055469C. As abyteit needed a(char)cast at each of those four tests; as acharit needs none. Size and offset don't change.UpdateDairyFarm(0x004167E0, 97.9% on main), stores small constants into it and compares it for equality. It reads the same with either type in both modes (the small builds above), so no full regression was run for this change.One line added to
cmake/compiler-flags-gl.txtUpdateDairyFarmer.cpp, for the default build: under/GLit sees the helper callees on main's list (IncrementAndOptionalUpdateAVValueRelated,SetStateToFreetimeWalking,ComputeGoodsProduced,hasUnitReachedDestinationand others). With the option on, the wrapper replaces it and the line has no effect.CheckUnitProductionPausedisn't on main's list. We left it off so that no other caller's default build changes, which is part of why the default build reads 85.2% here and read 93.9% on our development branch.Kept as they are
(short)on the slot stores (workers[...] = (short)DAT_CurrentUnitSlotID::instance), as main's unit functions write them.workplace: the original reloads it there (movsx eax, word ptr [edi + 0x1388884]at 0x00554C88), andbuildings[workplace]loses the match. A one-line comment says so.field_0x58 = 1stays a number. The checker matches the name to aBOOLEnumfield ofSoundEffectsHelperData1, butUnit::field_0x58is ashort.field_0x58,field_0x2ac,field_0x4f74), which we have nothing better for.Other PRs
cmake/compiler-flags-gl.txt, so whichever goes in second gets a one-line conflict there: keep both.Building'spathLinkageRelated2andgateState:renderDebugDataCurrentPlayerData,applyGateOrDrawbridgeOpenCloseChange,initializeGatePathfindingForOwner,updatePathLinkageTileMap,UpdateGateHouseLarge,UpdateGateHouseSmall,UpdateWoodGate1,findBestAttackTileByPathCost,resetTileAndClearMoat,GateOpenOrClose,ClickOpenOrCloseGate,TransformAndRenderPercentage. Both builds above left them out, with their resolvers off. This PR doesn't touch them.🤖 Generated with Claude Code